<template>
  <div class="tabbar-wrap">
    <van-tabbar v-model="active" class="tabbar" fixed>
      <van-tabbar-item v-for="(item, index) in tabList" :key="item.id" :name="item.to" @click="onTabClicked(item.to)">
        <template #icon>
          <van-icon :name="item.icon" />
        </template>
        {{ item.text }}
      </van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script lang="ts">
import {defineComponent} from "vue";

export default defineComponent({
  name: 'Tabbar',
});
</script>
<script lang="ts" setup>
import { computed, ref, unref, watchEffect } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useAppStore } from '@/store/app';
const router = useRouter();
const route = useRoute();
const appStore = useAppStore();

const active = ref('/home');
const tabBar = computed(() => appStore.getTabBar);
const tabList = computed(() => unref(tabBar));

watchEffect(() => {
  active.value = route.path;
});

const onTabClicked = (to:string) => {
  router.push({
    path: to
  })
}
</script>


<style lang="scss" scoped>
.tabbar-wrap {
  height: calc(50px + constant(safe-area-inset-bottom));
  height: calc(50px + env(safe-area-inset-bottom));
}

.tabbar {
  :deep(.van-tabbar-item--active) {
    .van-icon {
      animation: scale-icon 0.3s ease-in-out;
    }
  }

  @keyframes scale-icon {
    0% {
      transform: scale(1);
    }
    50% {
      transform: scale(0.8);
    }
    100% {
      transform: scale(1);
    }
  }
}
</style>
